<template>
	<view>

		<view v-if="payCostList.length > 0">

			<view class="item" v-for="(item, index) in payCostList" :key="index" @click="itemClick(item)">

				<view class="title-wrap">

					<text class="title">
						{{filterNull(item.rentTypeName)}}
					</text>

					<view class="title-warn">
						{{'付款金额：￥'+filterNull(item.uncollectedAmount)}}
					</view>
				</view>

				<u-line color="#efefef" dashed margin="0 0 15px"></u-line>

				<view class="text-line">
					<text class="text-name">车辆订单号:</text>
					<text class="text-value">{{filterNull(item.businessNo)}}</text>
				</view>


				<view class="text-line">
					<text class="text-name">租期:</text>
					<text
						class="text-value">{{filterNull(item.timeStartRent)}}至{{filterNull(item.timeFinishRent)}}</text>
				</view>

				<view class="text-line">
					<text class="text-name">车牌号:</text>
					<text class="text-value">{{filterNull(item.carPlateNo)}}</text>
				</view>

				<view class="text-line">
					<text class="text-name">品牌/车系/车型:</text>
					<text
						class="text-value">{{filterNull(item.brandName)}}/{{filterNull(item.seriesName)}}/{{filterNull(item.modelName)}}</text>
				</view>



				<view class="text-line">
					<text class="text-name">付款类型:</text>
					<text class="text-value">{{filterNull(item.collectionTypeName)}}</text>
				</view>


				<view class="text-line">
					<text class="text-name">记账周期:</text>
					<text class="text-value">{{filterNull(item.billStartTime)}}至{{filterNull(item.billEndTime)}}</text>
				</view>


				<view class="text-line">
					<text class="text-name">应付日期:</text>
					<text class="text-value">{{filterNull(item.receivableDate)}}</text>
				</view>


				<view class="text-line">
					<text class="text-name">逾期天数:</text>
					<text class="text-value">{{item.overdueDays?item.overdueDays + '天':'0'}}</text>
				</view>

				<view class="title-wrap"
					v-if="isEnv!=3 && item.uncollectedAmount>0">

					<view class="title-warn">
						费用单已出，请尽快还款
					</view>

					<view class="btn-detail" @click.stop="itemClick(item)">
						立即支付
					</view>
				</view>

			</view>

			<u-loadmore v-if="pageNo>2" :status="loadingStatus" @loadmore="clickloadmore"></u-loadmore>
		</view>

		<no-data v-else></no-data>

	</view>
</template>

<script>
	import {
		receivablelist,
		commonenv
	} from '../../../../common/api.js';

	export default {
		data() {
			return {
				isEnv: 0,
				pageNo: 1,
				loadingStatus: 'loading',
				payCostList: [],
			}
		},

		onShow() {
			this.pageNo = 1;
			this.getData();
			this.getEnv();
		},

		methods: {
			getEnv(){
				commonenv().then(res=>{
					this.isEnv = res;
				})
			},

			getData() {
				receivablelist({
					params: {
						pageNo: this.pageNo
					}
				}).then(res => {
					if (this.pageNo == 1) {
						this.payCostList = [];
						this.pageNo++;
						// uni.stopPullDownRefresh();

						this.loadingStatus = 'loadmore';
					} else {
						if (!uni.$u.test.isEmpty(res)) {
							this.pageNo++;

							this.loadingStatus = 'loadmore';
						} else {

							this.loadingStatus = 'nomore';
						}
					}

					if (!uni.$u.test.isEmpty(res)) {
						this.payCostList = this.payCostList.concat(res);
					}


				})
			},
			
			// pay(item){
			// 	uni.showLoading({
			// 		title: '加载中...',
			// 	})
			// 	uni.$u.http.post('app/pay', {
			// 		type: 1, //{2订单1缴费}
			// 		receivablesId: this.receivablesId, // 缴费id
			// 		orderCarId: '' // 订单id
			// 	}).then(res => {
			// 		console.log(res)
			// 		uni.hideLoading()
			// 		uni.requestPayment({
			// 			timeStamp: res.timeStamp,
			// 			nonceStr: res.nonceStr,
			// 			package: res.package,
			// 			signType: res.signType,
			// 			paySign: res.paySign,
			// 			success(res) {
			// 				console.log(res);
			// 				// uni.navigateBack()
			// 				this.pageNo = 1;
			// 				this.getData();
			// 			},
			// 			fail(res) {
			// 				uni.hideLoading()
			// 				uni.showToast({
			// 					title: '支付取消',
			// 					icon: 'none'
			// 				})
			// 			}
			// 		});
			// 	});
			// },
			
			itemClick(item){
				if(item.receivablesId){
					uni.navigateTo({
						url:'./billdetail?receivablesId='+item.receivablesId
					})
				}
			},
			
			clickloadmore() {
				this.getData();
				this.showloading = true;
				this.loadingStatus = 'loading';
			},
			

		},
		onPullDownRefresh() {
			this.pageNo = 1;
			this.getData();
		},

		onReachBottom() {
			console.log('到底了');

			this.getData();
			this.showloading = true;
			this.loadingStatus = 'loading';
		}

	}
</script>

<style lang="scss" scoped>
	
	.title-wrap {
		display: inline-flex;
		justify-content: space-between;
	}

	.title {
		width: 100%;
		height: 80upx;
		line-height: 80upx;
		font-size: 28upx;
		color: $black33;
	}

	.title-warn {
		color: #E93131;
		background-color: #FFFFFF;
		white-space: nowrap;
		text-align: center;
		font-size: 26upx;
		line-height: 60upx;
		margin: 10upx 0upx;
		align-self: flex-end;
	}
	
</style>
